from kafka import KafkaProducer
# 安装依赖  pip install kafka-python

if __name__ == '__main__':
    # 1、创建生产者
    producer = KafkaProducer(bootstrap_servers="master:9092,node1:9092,node2:9092")

    # 2、生产数据
    producer.send(topic="bigdata", value="大数据".encode("utf-8"))

    # 3、将数据刷新到kafka中
    producer.flush()

    # 4、关闭连接
    producer.close()
